package com.max.project.graphics.dao.impl;

import java.beans.PropertyVetoException;

import javax.sql.DataSource;

import org.apache.commons.dbutils.QueryRunner;

import com.max.common.util.PropUtil;
import com.max.common.util.StringUtil;
import com.mchange.v2.c3p0.ComboPooledDataSource;

/**
 * 
 * 项目名称:max-project-graphics
 * 文件名称:DaoSupport.java
 * 文件描述:
 * 创建人员:chenyibo
 * 创建时间:2013-1-23 下午01:46:56
 * 修改人员:chenyibo
 * 修改时间:2013-1-23 下午01:46:56
 * 修改备注:
 * @version V1.0
 */
public class DaoSupport 
{
	public static DataSource dataSource;
	
	public static QueryRunner runner;
	
	static
	{
		try 
		{
			ComboPooledDataSource cpds = new ComboPooledDataSource();
			cpds.setDriverClass(PropUtil.getProp("jdbc-c3p0", "jdbc.driverClass","org.gjt.mm.mysql.Driver"));
			cpds.setJdbcUrl(PropUtil.getProp("jdbc-c3p0", "jdbc.jdbcUrl","jdbc:mysql://127.0.0.1:3306/test"));
			cpds.setUser(PropUtil.getProp("jdbc-c3p0", "jdbc.user","root"));
			cpds.setPassword(PropUtil.getProp("jdbc-c3p0", "jdbc.password",""));
			cpds.setInitialPoolSize(StringUtil.convertInt(PropUtil.getProp("jdbc-c3p0", "jdbc.initialPoolSize",""), 2));
			cpds.setMinPoolSize(StringUtil.convertInt(PropUtil.getProp("jdbc-c3p0", "jdbc.miniPoolSize",""),2));
			cpds.setMaxPoolSize(StringUtil.convertInt(PropUtil.getProp("jdbc-c3p0", "jdbc.maxPoolSize",""),20));
			cpds.setAcquireIncrement(StringUtil.convertInt(PropUtil.getProp("jdbc-c3p0", "jdbc.acquireIncrement",""),2));
			cpds.setMaxIdleTime(StringUtil.convertInt(PropUtil.getProp("jdbc-c3p0", "jdbc.maxIdleTime",""),25000));
			
			dataSource = cpds;
			runner = new QueryRunner(dataSource);
		} 
		catch (PropertyVetoException e) 
		{
			e.printStackTrace();
		}
	}
}
